	<template>
	<el-container class="home-container">
		<!-- 头部区 -->
		<el-header>
			<div>
				<img src="../assets/icon_app.png" alt="" />
				<span>招生管理系统</span>
			</div>
			<div>
				<el-button type="infor" @click="logout">退出</el-button>
				<el-button type="info" @click="dialogPasswordFormVisible=true">修改密码</el-button>
			</div>
		</el-header>
		<!-- 页面主体区 -->
		<el-container>
			<!-- 侧边栏 -->
			<el-aside :width="isCollapse ? '64px' : '200px'">
				<!-- 顶端折叠按钮 -->
				<div class="toggle-button" @click="toggleCollapse">|||</div>
				<!-- 侧边栏菜单区域 -->
				<el-menu background-color="#333744" text-color="#fff" active-text-color="#409bff" :unique-opened="true"
					:collapse="isCollapse" :collapse-transition="false" :router="true" :default-active="activePath">
					<!-- 一级菜单 -->
					<el-submenu :index="item.Id+''" v-for="item in menulist" :key="item.Id">
						<!-- 一级菜单的模板区域 -->
						<template slot="title">
							<!-- 图标 -->
							<i :class="iconObj[item.Id]"></i>
							<!-- 文本 -->
							<span>{{item.Name}}</span>
						</template>
						<!-- 二级菜单 -->
						<el-menu-item v-if="subItem.ParentId==item.Id" :index="'/'+subItem.Path"
							v-for="subItem in menulist2" :key="subItem.id" @click="saveNavState('/'+subItem.Path)">
							<template slot="title">
								<!-- 图标 -->
								<i class="el-icon-menu"></i>
								<!-- 文本 -->
								<span>{{subItem.Name}}</span>
							</template>
						</el-menu-item>
					</el-submenu>

				</el-menu>
			</el-aside>
			<!-- 右侧内容主体 -->
			<el-main>
				<!--路由占位符  -->
				<router-view></router-view>
			</el-main>
		</el-container>
		<!-- 修改密码 -->
		<el-dialog title="修改密码" :visible.sync="dialogPasswordFormVisible">
			<el-form :model="Passwordform" ref="PasswordformRef" :rules="PasswordformRules"> 
				<el-form-item
				 label="旧密码" 
				 :label-width="formLabelWidth"
				 prop="password">
					<el-input type="password" v-model="Passwordform.password" auto-complete="off"></el-input>
				</el-form-item>
				<el-form-item label="新密码" :label-width="formLabelWidth" prop="newpassword">
					<el-input type="password" v-model="Passwordform.newpassword" auto-complete="off"></el-input>
				</el-form-item>
			</el-form>
			<div slot="footer" class="dialog-footer">
				<el-button @click="dialogPasswordFormVisible = false">取 消</el-button>
				<el-button type="primary" @click="submitPass">确 定</el-button>
			</div>
		</el-dialog>
		
	</el-container>
</template>

<script>
	export default {
		data() {
			return {
				// 左侧菜单数据
				menulist: [],
				menulist2: [],
				// 一级图标对象
				iconObj: {
					'125': 'iconfont icon-user',
					'103': 'iconfont icon-tijikongjian',
					'101': 'iconfont icon-shangpin',
					'102': 'iconfont icon-danju',
					'145': 'iconfont icon-baobiao'
				},
				PasswordformRules:{
					// 验证密码是否合法
					password: [{
							required: true,
							message: '请输入登录密码',
							trigger: 'blur'
						},
						{
							min: 6,
							max: 15,
							message: '长度在 6 到 15 个字符',
							trigger: 'blur'
						}
					],
					newpassword: [{
							required: true,
							message: '请输入登录密码',
							trigger: 'blur'
						},
						{
							min: 6,
							max: 15,
							message: '长度在 6 到 15 个字符',
							trigger: 'blur'
						}
					]
				},
				Passwordform:{},
				//是否折叠
				isCollapse: false,
				// 被激活的链接地址
				activePath: '',
				//修改密码的弹框
				dialogPasswordFormVisible:false,
				formLabelWidth:"120px"
			}
		},
		created() {
			this.getMenuList()
			this.activePath = window.sessionStorage.getItem('activePath')
		},
		methods: {
			logout: function() {
				window.sessionStorage.clear();
				this.$router.push("/login");
			},
			// 获取所有的菜单
			async getMenuList() {
				const {
					data: res
				} = await this.$http.post('api/LeftMenus/menus', {
					Id: parseInt(window.sessionStorage.getItem("token"))

				})
				if (res.code != 0) return this.$message.error(res.msg)
				this.menulist = res.data1
				this.menulist2 = res.data2
				//console.log(res.data2);
			},
			//点击按钮，切换菜单的折叠与展开
			toggleCollapse() {
				this.isCollapse = !this.isCollapse
			},
			// 保存链接的激活状态
			saveNavState(activePath) {
				window.sessionStorage.setItem('activePath', activePath)
				this.activePath = activePath
			},
			//修改密码
		  async submitPass(){
			 const {data:res}=await this.$http.post('api/Login/password',{
					 password:this.Passwordform.password,
					 newpassword:this.Passwordform.newpassword,
					 Id: parseInt(window.sessionStorage.getItem("token"))	
			 })	
			 // console.log(res);
			 if(res.code!=0) return this.$message.error(res.msg);
			 
			 this.$message.success(res.msg)
			 this.dialogPasswordFormVisible=false
			 this.$router.push("/login");
			}

		}
	}
</script>

<style lang="less" scoped="scoped">
	.home-container {
		height: 100%;
	}

	.el-header {
		background-color: #373d41;
		display: flex;
		justify-content: space-between;
		padding-left: 0;
		align-items: center;
		color: #fff;
		font-size: 20px;

		>div {
			display: flex;
			align-items: center;

			span {
				margin-left: 15px;
			}
		}
	}

	.el-aside {
		background-color: #333744;

		.el-menu {
			border-right: none;
		}
	}

	.el-main {
		background-color: #eaedf1;
	}

	.iconfont {
		margin-right: 10px;
	}

	.toggle-button {
		background-color: #4a5064;
		font-size: 10px;
		line-height: 24px;
		color: #fff;
		text-align: center;
		letter-spacing: 0.2em; //三条线之间的距离
		cursor: pointer; //鼠标触及变小手
	}
</style>
